package com.ky.tms.controller;


import com.ky.tms.entity.TmsDriver;
import com.ky.tms.entity.TmsOil;
import com.ky.tms.exception.PredictableException;
import com.ky.tms.service.ITmsDriverService;
import com.ky.tms.service.ITmsOilService;
import com.ky.tms.util.CommonResult;
import com.ky.tms.util.JwtUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2020-05-13
 */
@RestController
@RequestMapping("/tms/tms-oil")
public class TmsOilController {

    @Autowired
    private ITmsOilService tmsOilService;

    @ApiOperation("油卡数据分页")
    @GetMapping("page")
    public CommonResult page(TmsOil tmsOil, @RequestParam Long pageSize, @RequestParam Long current, HttpServletRequest request){
        return CommonResult.buildSuccess(tmsOilService.page(tmsOil, pageSize, current));
    }

    @ApiOperation("创建油卡")
    @PostMapping
    public CommonResult add(@RequestBody TmsOil tmsOil) throws PredictableException {
        tmsOilService.add(tmsOil);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("修改油卡")
    @PutMapping
    public CommonResult update(@RequestBody TmsOil tmsOil) throws PredictableException {
        tmsOilService.update(tmsOil);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("删除油卡")
    @DeleteMapping
    public CommonResult delete(@RequestBody List<Long> ids, HttpServletRequest request){
        tmsOilService.delete(ids);
        return CommonResult.buildSuccess(null);
    }

    @ApiOperation("搜索下拉数据")
    @GetMapping("select-list")
    public CommonResult selectList(TmsOil tmsOil) {
        return CommonResult.buildSuccess(tmsOilService.selectList(tmsOil));
    }

    @ApiOperation("油卡充值")
    @PostMapping("pay")
    public CommonResult pay(@RequestBody TmsOil tmsOil) throws PredictableException {
        tmsOilService.pay(tmsOil);
        return CommonResult.buildSuccess(null);
    }

}
